package com.sky.demo.java.thread;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ThreadLocalTest {

    public static final ThreadLocal<SimpleDateFormat> dateFormat = ThreadLocal.withInitial(()->new SimpleDateFormat("yyyy-MM-dd"));


    public static void main(String[] args) {
        for(int i = 0; i < 10; i++){
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    String format = dateFormat.get().format(new Date());
                    System.out.println(format + " thread name = " + Thread.currentThread().getName());
                }
            };
            Thread thread = new Thread(runnable);
            thread.start();
        }
    }
}
